#   1、编写一个学生方法，产生一堆学生对象（姓名），传入形参控制学生生成数量
from faker import Faker
faker = Faker(locale='zh_cn')
import time
import json
'''
def stu_name():
    n = int(input("请输入"))
    for i in range(n):
        faker = Faker(locale='zh_cn')
        print(faker.name())
result = stu_name()
print(result)
'''
#2、创建一个方法，用来生成普通人必备的信息：姓名、年龄、住址、身份证号、手机号，随机生成20个写入personinfo.txt里
#格式：姓名：xxx  年龄：xxx 住址：xxx 身份证号：xxx
'''
def info_name():
    for i in range(20):
        info = dict.fromkeys(['姓名', '年龄', '地址', '身份证', '手机号',])
        name = faker.name()
        info['姓名'] = name
        addr = faker.address()
        info['地址'] = addr
        ssn = faker.ssn(min_age=18,max_age=90)
        info['身份证'] = ssn
        phon = faker.phone_number()
        info['手机号'] = phon
        print(info)
        with open('student1.txt', 'at',encoding='utf-8')as f:
            json.dump(info,f)
info_name()
'''

#3.文本 student.txt中包含下面的内容
#zhangshan:30
#lisi:50
#wangwu:60
#lifei:70
#期望能够统计出其中的内容以dict的形式保存，例如：
#{"zhangshan":30,"lisi":50,"wangwu":60,"lifei":70}
#with open('student.txt','w',encoding='utf-8') as f:
#    f.writelines(['zhangshan:30\n','lisi:50\n','wangwu:60\n','lifei:70'])

#4.给你一个 非空 整数数组 nums ，除了某个元素只出现一次以外，其余每个元素均出现两次。找出那个只出现了一次的元素。
'''
nums = [11,11,22,22,33,33,44]
for i in nums:
    if nums.count(i) == 1:
        print(i)
'''
'''
nums = [11,11,22,22,33,33,44]
def Number(nums):
    result = 0
    for num in nums:
        result ^= num
    return result
print(Number(nums))
'''
#5.输入：["1","a","b","3","5","8","_"] 想要提取里面得数字，并保存到一个列表中
'''
num1 = ["1","a","b","3","5","8","_"]
for i in num1:
    if i.isdigit():
        numbers.append(int(i))
'''
#6.写函数,函数接收的4个参数分别是:姓名,性别(默认为男),年龄,地址
#用户通过input输入这4个内容(支持持续输入,Q或q退出),并传递给函数
#函数接收到这些内容,将其追加到student_msg文件中
'''
def Input(name,gender,age,address):
    with open('student_msg.txt', 'a') as f:
        f.write(f'姓名: {name}\n')
        f.write(f'性别: {gender}\n')
        f.write(f'年龄: {age}\n')
        f.write(f'地址: {address}\n')
while True:
    name = input('请输入姓名')
    gender = input("请输入性别（默认为男）：")
    age = input("请输入年龄：")
    address = input("请输入地址：")
    if name == 'Q' or name == 'q':
        break
    Input(name,gender,age,address)
'''
#7、打印功能菜单、添加学生信息、删除学生信息、修改学生信息、显示学生信息、退出系统，并且需要接收用户的输入，在根据输入内容调用相应函数实现相应功能（存入文件），模板图如下。每次对学生管理系统发生改动，要写入改动点到log.txt文本中
'''
def super_student_manager(logs):
    with open('log.txt','a',encoding='utf-8')as f:
        times = time.strftime("%Y-%m-%d %H:%M:%S")
        f.write(f'{logs},{times}\n\n')

student = []
while True:
    request = input('你想干啥：')
    if request == '功能菜单':
        print('添加学生信息\n删除学生信息\n修改学生信息\n显示学生信息\n退出系统')
    elif request == '添加学生信息':
        id1 = len(student)+1
        num = len(student)
        name = input('姓名：')
        age = input('年龄：')
        sex = input('性别：')
        student.insert(num, [id1,name,sex,age])
        print('添加成功')
        logs = f'添加学生信息,{id1},{name},{sex},{age}'
    elif request == '删除学生信息':
        d1 = int(input('请输入要删除的学生id：'))
        logs = f'删除{student[d1 - 1]}'
        del student[d1 - 1]
        print('删除成功')
    elif request == '修改学生信息':
        b1 = int(input('请输入学生id：'))
        name1 = input('姓名：')
        age1 = input('年龄：')
        sex1 = input('性别：')
        student[b1-1] = [b1,name1,sex1,age1]
        logs = f'修改{student[b1-1]}为{[b1,name1,sex1,age1]}'
        print('修改成功')
    elif request == '显示学生信息':
        print(student)
    else:
        print('指令不存在')
    if request == '退出系统':
        break
    super_student_manager(logs)
    '''
#8.

def friend(logs):
    with open('friend_logs.txt','w',encoding='utf-8')as f:
        f.write(f'{logs}')
friend_list = set()
while True:
    request = input('1.添加好友\n2.删除好友\n3.备注好友\n4.展示好友\n5.退出\n请输入您的选项：')
    if request == '1':
        friend_name = input('请输入好友昵称：')
        friend_list.add(f'{friend_name}')
        print('好友添加成功')
        logs = friend_list
        friend(logs)
    elif request == '2':
        delete = input('请输入要删除的好友昵称:')
        friend_list.remove(f'{delete}')
        print('删除成功')
        logs = friend_list
        friend(logs)
    elif request == '3':
        front = input('请输入要修改的好友姓名：')
        before = input('请输入修改后的好友姓名：')
        friend_list.remove(f'{front}')
        friend_list.add(f'{before}')
        print('备注成功')
        logs = friend_list
        friend(logs)
    elif request == '4':
        with open('friend_logs.txt','r',encoding='utf-8')as f:
            if f.read() is None:
                print('好友列表为空')
            else:
                print(f.read())
    elif request == '5':
        break


